<template>
	<view>
		<view class="list">
			<view class="item" v-for="(item,index) in list">
				<u--image :showLoading="true" :src="item.img" width="200rpx" height="150rpx"></u--image>
				<view class="info">
					<view class="title">{{item.title}}</view>
					<view class="price">
						<text class="price-num">{{item.price}}</text>
						<text class="unit">{{item.unit}}</text>
					</view>
				</view>
			</view>
		</view>
		<view  v-if="list.length == 0">
			<u-empty mode="list"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				region_name:'',
				list: [],
				current:0,
				is_more: 0,
				query: {
					region_id: '',
					type: undefined,
					page: 1,
					size: 10
				},
			};
		},
		onReachBottom() {
			if (this.is_more) {
				this.getPageFun();
			}
		},
		onShow(){
			uni.$once("city",(data)=>{
				this.region_name = data.region_name;
				this.query.region_id = data.region_id;
				uni.setStorageSync("CITYDATA",data);
			})
			
			if(!uni.getStorageSync("CITYDATA")){
				this.toSelectCity();
			}else{
				var data = uni.getStorageSync("CITYDATA");
				this.region_name = data.region_name;
				this.query.region_id  = data.region_id;
			}
			this.getPageFun();
		},
		onLoad(e) {
			if(e&&e.type) this.query.type = e.type;
		},
		methods:{
			
			getPageFun() {
				var _this = this;
				uni.$u.http.post('/Info/page',{...this.query}).then(async res =>{
					let curPageData = res.lists;
					if (this.query.page == 1) {
						_this.list = [];
					}
					if (res.is_more) {
						_this.query.page++;
					}
					_this.is_more = res.is_more;
					_this.list = _this.list.concat(curPageData);
				}).catch(err => {
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.list{
		padding: 0 30rpx;
		.item{
			margin-top: 30rpx;
			display: flex;
			.info{
				flex: 1;
				margin-left: 30rpx;
				.title{
					font-size: 32rpx;
				}
				.price{
					.price-num{
						font-size: 36rpx;
						font-weight: 600;
						color: red;
					}
					.unit{
						font-size: 24rpx;
					}
				}
			}
		}
	}
</style>
